<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jQuery.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 600px;
            border: 2px solid black;
            margin: 100px auto;
            text-align: center;
            padding-bottom: 20px;
        }

        textarea {
            width: 300px;
            height: 150px;
            resize: none;
            vertical-align: bottom;
            margin-top: 20px;
        }

        ul {
            margin-top: 10px;
            margin-left: 167px;
            width: 300px;
        }

        ul li {
            display: none;
            text-align: left;
            width: 300px;
            border-bottom: dashed 1px;
            list-style: none;
        }

        ul li a {
            float: right;
        }
    </style>
</head>

<body>
    <div class="box">
        <span>微博发布</span>
        <textarea></textarea>
        <button>发布</button>
        <ul>
        </ul>
    </div>

    <script>
        $(function () {
            $("button").on({
                "click": function () {
                    if ($("textarea").val() === "") {
                        alert("您未输入");
                        return false;
                    }
                    var li = $("<li></li>");
                    li.html($("textarea").val() + "<a href='javascript:;'>删除</a>")
                    $("ul").prepend(li);
                    li.slideDown();
                    $("textarea").val("");
                }
            });
            $("ul").on("click", "a", function () {//一定要用on哦，要使用事件委托
                $(this).parent().slideUp(function () {
                    $(this).remove();
                });
            })
        })
    </script>
</body>

</html>